package org.example.bigdata.utils;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class Result {
    private int code;  //状态码
    private String msg;  //提示信息
    private Object data;  //数据

    //操作成功，状态码固定为200，提示信息固定为”操作成功“
    public static Result success(Object data) {
        return Result.success(200, "操作成功", data);
    }

    public static Result success() {
        return Result.success(200, "操作成功", null);
    }

    public static Result success(int code, String msg, Object data) {
        Result res = new Result();
        res.setCode(code);
        res.setMsg(msg);
        res.setData(data);
        return res;
    }

    //操作失败，状态码固定为400，固定无法获取数据
    public static Result fail(String msg) {
        return Result.fail(400, msg, null);
    }

    //操作失败，状态码固定为400，固定无法获取数据
    public static Result fail(int code,String msg) {
        return Result.fail(code, msg, null);
    }

    public static Result fail(int code, String msg, Object data) {
        Result res = new Result();
        res.setCode(code);
        res.setMsg(msg);
        res.setData(data);
        return res;
    }
}